package com.tj.test.sys.service.impl;

import com.tj.test.sys.dao.ClassMapper;
import com.tj.test.sys.po.Classc;
import com.tj.test.sys.service.IClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ClassService implements IClassService {
    @Autowired
    private ClassMapper mapper;

    @Override
    //查询所有班级信息
    public List<Classc> selectAllClass() {
        List<Classc> list=new ArrayList<>();
        if (!mapper.selectAllClass().isEmpty()){
            list=mapper.selectAllClass();
        }
        return list;
    }

    @Override
    //插入班级信息
    public int insertClass(Classc classc) {
        int temp=0;
        /* 业务判断
         * （1）人员名称不能重复
         * （2）增加人员之前先查询*/
        try{
            temp=mapper.selectClassByNameCount(classc);
            if (temp<1){
                temp=mapper.insertClass(classc);
            }else{
                return temp;
            }
        }catch (Exception e){
            return -2;
        }
        return temp;
    }

    @Override
    //删除班级信息
    public int deleteClass(Classc classc) {
        int temp=0;
        try{
        temp=mapper.selectClassByNameCount(classc);
        if (temp>0){
            temp=mapper.deleteClass(classc);
        }else{
            return -2;
        }
        }catch (Exception e){
            return -1;
        }
        return temp;
    }

    @Override
    //修改班级信息
    public int updateClass(Classc classc) {
        int temp=0;
        try{
            temp=mapper.selectClassByNameCount(classc);
            if (temp<1){
                temp=mapper.updateClass(classc);
            }else{
                return temp;
            }
        }catch (Exception e){
            System.out.println(e.getStackTrace());
            return -1;
        }
        return temp;
    }


     /*@Override
    //根据班级名称查询班级信息
    public int selectClassByNameCount(Classc classc) {
        int temp=0;
        if (mapper.selectClassByNameCount(classc)!=0)
            temp=mapper.selectClassByNameCount(classc);
        return temp;
    }
*/
}
